package com.xqb.modules.controller.course;

import com.xqb.common.annotation.RepeatSubmit;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.modules.domain.dto.RecommendParamsDto;
import com.xqb.modules.domain.dto.SearchParamsDto;
import com.xqb.modules.domain.pojo.es.EsCourse;
import com.xqb.modules.service.EsCourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: JinChen Zhu
 * @CreateTime: 2024-10-28  20:21
 */
@RestController
@RequestMapping("/search/esCourse")
@Slf4j
public class EsCourseController extends BaseController {
    @Autowired
    private EsCourseService esCourseService;

    @RepeatSubmit
    @PostMapping("/importAll")
    public AjaxResult importAll() {
        return AjaxResult.success(esCourseService.importAll());
    }

    @PostMapping("/search")
    public TableDataInfo search(@RequestBody SearchParamsDto spd) {
        log.info("spd:{}", spd);
        Page<EsCourse> coursePage = esCourseService.search(spd);
        long total = coursePage.getTotalElements();
        List<EsCourse> data = coursePage.getContent();
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setTotal(total);
        tableDataInfo.setRows(data);
        return tableDataInfo;
    }

    @GetMapping("/recommend")
    public AjaxResult recommend(@RequestBody RecommendParamsDto rpd) {
        return AjaxResult.success(esCourseService.recommend(rpd));
    }

}
